package com.izanpin.common.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by St on 2017/2/24.
 */
public class SHA {
    public static String toSHAString(String str) throws NoSuchAlgorithmException {
        String plaintext = str;
        MessageDigest m = MessageDigest.getInstance("SHA");
        m.reset();
        m.update(plaintext.getBytes());
        byte[] digest = m.digest();
        BigInteger bigInt = new BigInteger(1, digest);
        String hashtext = bigInt.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
        while (hashtext.length() < 32) {
            hashtext = "0" + hashtext;
        }

        return hashtext;
    }
}
